class UsersController < ApplicationController

  before_filter :require_no_user, :only => [:new, :create]
  before_filter :require_user, :only => [:show]

  def index
    redirect_to root_url
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new
    if @user.signup!(params)
      @user.deliver_activation_instructions!
      flash[:notice] = "Registration successful."
      redirect_to root_url#:controller => "users", :action => "show", :id => @user.id
    else
      render :action => "new"
    end
  end

  def show
    if params[:id].nil?
      @user = current_user
    else
      if params[:id].to_str != current_user.id.to_s
        begin
          @user = User.find(params[:id])
        rescue ActiveRecord::RecordNotFound
          redirect_to :id => current_user.id
        end
      else
        @user = current_user
      end
    end
  end
end
